{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}
{#{% import "user/partial/search_user_form.html" as search_user_form_macro %}#}
{#{% import "user/partial/user_table.html" as user_table_macro %}#}

{% block title %}万屏时代OPC--代金券赠送明细{% endblock %}

{% block panel_heading %}
    万屏时代OPC--代金券赠送明细
{% endblock %}

{% block panel_body %}
    <form id="search-user-form" action="{{ url_for('op_bp.give_voucher_list') }}"
          method="post" class="form" role="form">
        {{ my_wtf_macros.form_field(form.grant_date, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.user_id, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.nickname, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.operator_id, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.reason, div_col=4, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div class="pull-right btn-group">
            <button type="submit" class="btn btn-info">
                查询
            </button>
            {% if not current_user.is_agent %}
                <a
                        href="javascript:void(0);"
                        target="_blank"
                        class="btn-group btn btn-primary"
                        id="export-voucher-info"
                >
                    导出
                </a>
            {% endif %}
        </div>
    </form>

    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, 'op_bp.give_voucher_list', **url_kwargs) }}
    </div>
    {% endif %}

    {% if pagination %}
        <table id="cancel-attention-user-info-table"
               class="table table-bordered table-hover table-condensed table-striped">
            <thead>
            <tr>
                <th>受赠人ID</th>
                <th>受赠人姓名</th>
                <th>赠送券额</th>
                <th>赠送人</th>
                <th>赠送理由</th>
                <th>赠送时间</th>
                <th>过期时间</th>
                <th>代金券状态</th>
            </tr>
            </thead>
            <tbody>
            {% for each in records %}
                <tr>
                    <td>{{ each.gifted_user.id }}</td>
                    <td>{{ each.gifted_user.nickname }}</td>
                    <td>{{ each.bid_point }}</td>
                    <td>{{ each.operator.nickname }}</td>
                    <td>{{ each.reason_display }}</td>
                    <td>{{ each.grant_date }}</td>
                    <td>{{ each.expired_date }}</td>
                    <td>{{ each.status_display }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    {% endif %}

    {% if pagination %}
        <div class="pagination">
            {{ macros.pagination_widget(pagination, 'op_bp.give_voucher_list', **url_kwargs) }}
        </div>
    {% endif %}

{% endblock %}

{% block scripts %}
    {{ super() }}
    <script>
        $(document).ready(function () {
            $("#export-voucher-info").click(function () {
                var url = '{{ url_for('op_bp.export_give_voucher_list') }}';
                url = url + '?' + 'mobile=' +$('#mobile').val()+
                    '&grant_date=' + $('#grant_date').val() +
                    '&operator_id=' + $('#operator_id').val() +
                    '&reason=' + $('#reason').val();
                window.location.href = url;
            });
        })
    </script>
{% endblock %}
